function STM = State2STM(t,S,u)

I = eye(6);
%[] Define identity matrix.

Yo = zeros(42,1);
%[] Pre-allocate memory for 6x7 matrix.
%   They must be written in 42x1 matrix to be integrated using ode45 

for i=1:6
   for j=1:6
      Yo(6*(i-1)+j)=I(i,j); 
   end    
end   
%[] Express STM in column vector

Xo = S(:,1);
%[] Initial state.

Yo(37:42) = Xo;
%[] Input initial states at the end of the initial condition of the STM

options=odeset('RelTol',1e-6,'AbsTol',1e-9);       
%[] Set desired tolerence

[~,Y]=ode113(@(t,Y)STM_CR3BP(t,Y,u),t,Yo,options);  
%[] Integrate the State Transition Matrix along the trajectory.

Y = Y';
%[] Transpose to column vector.

STM_tf_temp = Y(1:36,end);
%[] set the STM at t_f expressed as column vector at the end of the
%integrated value sets.

STM_tf = zeros(6);
%[] Desired shape.

for i=1:6
    for j=1:6
        STM_tf(i,j)=STM_tf_temp(6*(i-1)+j);
    end    
end
%[] Reshape the STM at t_f

STM = STM_tf;
%[] Output State Transition Matrix is 6x6 matrix

end